package com.kpx.app.wigdet;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kpx.app.R;
import com.kpx.app.wigdet.payment.GridPasswordView;

/**
 * 密码输入对话框
 *
 * @author scott
 */
public class DialogWithdrawInputPwd extends BaseDialog {
    private ImageView closeView;
    private GridPasswordView passwordView;
    private TextView txtOperate;
    private TextView txtAmount;
    private OnInputListener onInputListener;

    public interface OnInputListener {
        void inputDone(String pwd);
    }

    public DialogWithdrawInputPwd(Context context) {
        super(context);
        setContentView(R.layout.fragment_withdraw_pwd_dialog);
        initView();
    }

    private void initView() {
        closeView = (ImageView) findViewById(R.id.closeImageView);
        passwordView = (GridPasswordView) findViewById(R.id.payPasswordView);
        txtOperate = (TextView) findViewById(R.id.messageView);
        txtAmount = (TextView) findViewById(R.id.totalPayPriceView);
        closeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        passwordView.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {

            @Override
            public void onChanged(String pwd) {
            }

            @Override
            public void onMaxLength(String pwd) {
                if (null != onInputListener) {
                    onInputListener.inputDone(pwd);
                }
            }
        });
    }

    public void setOnInputListener(OnInputListener onInputListener) {
        this.onInputListener = onInputListener;
    }

    public void setOperateText(String text) {
        txtOperate.setText(text);
    }

    public void setAmount(String amount) {
        txtAmount.setText( amount);
    }

    @Override
    public void show() {
        super.show();
        passwordView.clearPassword();
    }

    public void showSoftKeyboard() {
        passwordView.forceInputViewGetFocus();
    }
}
